const express = require('express')

const images = express.Router()

// 导入路由处理模块
const img_hanlder = require('../handle-images/addImages')

//导入multer和path
const multer = require('multer')
const path = require('path')

//获取到file文件信息进行整理
const storage = multer.diskStorage({
    destination: function (req, file, cb) {
      // 指定文件存储的目录
      cb(null, path.join(__dirname, '../uploads'));
    },
    filename: function (req, file, cb) {
      // 指定文件存储时的文件名
      cb(null, `${Date.now()}.${file.mimetype.split('/')[1]}`);
    }
  });
  
  // 使用自定义存储引擎
  const uploads = multer({ storage: storage });


//添加图片
images.post('/addImages', uploads.single('img'), img_hanlder.addImages)

// 获取图片
images.post('/getImages', img_hanlder.getImages)

// 删除图片
images.post('/deleteImages', img_hanlder.deleteImages)


module.exports = images